from django.db import models
from django.contrib.auth.models import AbstractUser
from common.db import BaseModel


class User(AbstractUser, BaseModel):
    """用户模型
    继承用户模型，，并且继承baseModel(减少代码冗余)
    """
    mobile = models.CharField(max_length=111, default='', verbose_name='手机号')
    avatar = models.ImageField(verbose_name='用户头像', blank=True, null=True)

    class Meta:
        db_table = 'users'
        verbose_name = '用户表'


class Addr(models.Model):
    """"收货地址模型"""
    user = models.ForeignKey('User', verbose_name='用户所属地址', on_delete=models.CASCADE)
    phone = models.CharField(max_length=11, verbose_name='电话号码',default='')
    name = models.CharField(max_length=20, verbose_name='收货人姓名')
    province = models.CharField(max_length=20, verbose_name='省份')
    city = models.CharField(max_length=20, verbose_name='城市')
    county = models.CharField(max_length=20, verbose_name='区县')
    address = models.CharField(max_length=200, verbose_name='详细地址')
    id_default = models.BooleanField(verbose_name='是否为默认地址', default=False)


class Area(models.Model):
    """地区模型"""
    pid = models.ImageField(verbose_name='上级id')
    name = models.CharField(max_length=20, verbose_name='地区名称')
    level = models.CharField(max_length=20, verbose_name='等级')


class VerifCode(models.Model):
    """"验证码模型"""
    mobile = models.CharField(verbose_name='电话号码', max_length=11)
    code = models.CharField(verbose_name='验证码', max_length=6)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
